import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },

  // 栏目管理
  {
    path:'/category',
    component: Layout,
    children:[
      {
        path:'index',
        name:'categoty',
        component:()=>import('@/pages/category/index'),
        meta:{title:'栏目管理',icon:'jingpinlanmuguanli'}
      }
    ]
  },

  // 产品管理
  {
    path:'/product',
    component: Layout,
    children:[
      {
        path:'index',
        name:'product',
        component:()=>import('@/pages/product/index'),
        meta:{title:'产品管理',icon:'chanpinxinxi-'}
      }
    ]
  },

  // 账单管理
  {
    path:'/bill',
    component: Layout,
    meta:{title:'账单管理',icon:'zhangdan'},
    children:[
      {
        path:'coustomer',
        name:'coustomer',
        component:()=>import('@/pages/bill/coustomer'),
        meta:{title:'顾客账单'}
      },
      {
        path:'employee',
        name:'employee',
        component:()=>import('@/pages/bill/employee'),
        meta:{title:'员工账单'}
      },
      {
        path:'system',
        name:'system',
        component:()=>import('@/pages/bill/system'),
        meta:{title:'系统账单'}
      },
    ]
  },

  // 订单管理
  {
    path:'/order',
    component: Layout,
    children:[
      {
        path:'index',
        name:'order',
        component:()=>import('@/pages/Order/index'),
        meta:{title:'订单管理',icon:'dingdan'}
      }
    ]
  },

  // 审核大厅
  {
    path:'/Check',
    component:Layout,
    meta:{title:'审核大厅',icon:'zhinengshenheshenchashenhe'},
    children:[
      {
        path:'Account',
        name:'Account',
        component:()=>import('@/pages/Check/Account'),
        meta:{title:'账户变更'}
      },
      {
        path:'Certification',
        name:'Certification',
        component:()=>import('@/pages/Check/Certification'),
        meta:{title:'实名认证'}
      },
      {
        path:'Comments',
        name:'Comments',
        component:()=>import('@/pages/Check/Comments'),
        meta:{title:'订单评论'}
      },
      {
        path:'Information',
        name:'Information',
        component:()=>import('@/pages/Check/Information'),
        meta:{title:'资讯评论'}
      }
    ]
  },
  
  // 顾客管理
  {
    path:'/Customer',
    component:Layout,
    children:[
      {
        path:'index',
        name:'Customer',
        component:()=>import('@/pages/Customer/index'),
        meta:{title:'顾客管理',icon:'guke'},
      }
    ]
  },
  // 员工管理
  {
    path:'/Employees',
    component:Layout,
    meta:{title:'员工管理',icon:'mofanyuangong'},
    children:[
      {
        path:'yuangong',
        name:'Employees',
        component:()=>import('@/pages/Employees/yuangong'),
      },
      {
        path: '/Employees/details',
        name: 'details',
        component: () => import('@/pages/Employees/details'),
      },
    ]
  },

  // 网站资讯
  {
    path:'/WebInformation',
    component: Layout,
    meta:{title:'网站资讯',icon:'WEBSITE'},
    children:[
      {
        path:'categoty',
        name:'categoty',
        component:()=>import('@/pages/WebInformation/categoty'),
        meta:{title:'资讯分类'}
      },
      {
        path:'information',
        name:'information',
        component:()=>import('@/pages/WebInformation/information'),
        meta:{title:'资讯信息'}
      },
    ]
  },

  // 角色管理
  {
    path:'/Role',
    component: Layout,
    meta:{title:'角色权限',icon:'jiaoseguanli'},
    children:[
      {
        path:'permissions',
        name:'permissions',
        component:()=>import('@/pages/Role/permissions'),
        meta:{title:'权限管理'}
      },
      {
        path:'roleManager',
        name:'roleManager',
        component:()=>import('@/pages/Role/roleManager'),
        meta:{title:'角色管理'}
      },
      {
        path:'userManager',
        name:'userManager',
        component:()=>import('@/pages/Role/userManager'),
        meta:{title:'用户管理'}
      },
    ]
  },

  // 轮播管理
  {
    path:'/Carousel',
    component:Layout,
    children:[
      {
        path:'index',
        name:'Carousel',
        component:()=>import('@/pages/Carousel/index'),
        meta:{title:'轮播管理',icon:'lunbo'},
      }
    ]
  },

  // 系统管理
  {
    path:'/System',
    component:Layout,
    children:[
      {
        path:'index',
        name:'System',
        component:()=>import('@/pages/System/index'),
        meta:{title:'系统配置',icon:'xitongshezhi'},
      }
    ]
  },

  // 日志管理
  {
    path:'/Log',
    component:Layout,
    children:[
      {
        path:'index',
        name:'Log',
        component:()=>import('@/pages/Log/index'),
        meta:{title:'日志管理',icon:'rizhi'},
      }
    ]
  },

  // 个人信息
  {
    path:'/Personal',
    component:Layout,
    children:[
      {
        path:'index',
        name:'Personal',
        component:()=>import('@/pages/Personal/index'),
        meta:{title:'个人信息',icon:'geren'},
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
